﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutomationTools.Procedimentos.Leitura.Helper;
using System.Windows.Forms;

namespace AutomationTools.Procedimentos.FormsHelper
{
    public class PreencherComboBox : IProcedimento
    {
        InputSelect select;
        ComboBox comboBox;
        public PreencherComboBox(InputSelect select, ComboBox comboBox)
        {
            this.select = select;
            this.comboBox = comboBox;
        }

        public object Executar(IContexto contexto)
        {
            var retSelect = (Select)select.Executar(contexto);
            comboBox.DataSource = retSelect.Options;
            comboBox.Tag = retSelect.Name;
            comboBox.DisplayMember = "Text";
            comboBox.ValueMember = "Value";
            
            var selected = retSelect.Options.FirstOrDefault(x => x.Selected);
            if (selected != null)
                comboBox.SelectedValue = selected.Value;

            return contexto.Parametro;
        }

        public void ValidarEntrada(IContexto contexto)
        {
            throw new NotImplementedException();
        }
    }
}
